package stark.app.function.applock;

import android.widget.Switch;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.applock.lib.AppLockBean;

import org.jetbrains.annotations.NotNull;

import stark.app.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

/**
 * Author：daizhongbin on 2022/8/4
 * Email：1027154338@qq.com
 * Desc:
 */
public class AppAdapter extends StkProviderMultiAdapter<AppLockBean> {

    public AppAdapter() {
        super(1);
        addItemProvider(new MyItemProvider());
    }

    private class MyItemProvider extends BaseItemProvider<AppLockBean> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_app_lock;
        }

        @Override
        public void convert(@NotNull BaseViewHolder holder, AppLockBean bean) {
            holder.setImageDrawable(R.id.ivIcon, bean.appIcon);
            holder.setText(R.id.tvLabel, bean.appName);
            Switch switchLock = holder.getView(R.id.switchLock);
            switchLock.setChecked(bean.isLocked);
            switchLock.setOnClickListener(v -> {
                if (getOnItemClickListener() != null) {
                    getOnItemClickListener().onItemClick(AppAdapter.this, holder.itemView, holder.getAdapterPosition());
                }
            });
        }
    }

}
